/**
 * Created by chenweicheng on 1/3/2017.
 */
/**
 * Created by Administrator on 2016/12/20 0020.
 */

import React, {Component} from 'react';
import {AppRegistry, View, Text, ScrollView, Image, StyleSheet, TouchableHighlight,Platform} from 'react-native';
import RNImageUtil from '../RNImageUtil';

export default class TestRnImageUtil extends Component {

    constructor(props) {
        super(props)
        //  this.state = {screenSource: null}
        this.source = null;
        reload = false;
    }


    handleScreenShot = () => {
        RNImageUtil.screenshot(
            100 * 2, 200 * 2, 260 * 2, 400 * 2).then((uri) => {
            console.log("uri" + uri);
            console.log('success generating fixed image');

            if (Platform.OS === 'android') {
                this.source = {uri: uri, isStatic: true};
            } else {
                this.source = {
                    uri: uri.replace('file://', ""),
                    isStatic: true
                }
            }
            this.setState({
                reload: true
            })
        }, (error) => {
            console.log('error generating fixed image');
        })

    };

    render() {
        return (
            <View style={styles.container}>

                <Image
                    source={this.source}
                    style={{
                    alignSelf: 'center',
                    width:160,
                    height:400
                }}
                >
                </Image>
                <TouchableHighlight style={{padding: 20, backgroundColor: '#ccc'}}
                                    onPress={() =>this.handleScreenShot()  }>
                    <Text>ScreentShot</Text>
                </TouchableHighlight>
            </View>
        );
    }
}
var styles = StyleSheet.create({
    container: {
        //   justifyContent: 'center',
        flex: 1,
        flexDirection: 'column',//没有flexDirection这个属性的话，justifyContent不会生效
        justifyContent: 'center',
        padding: 15,
        alignItems: 'center'
    }
});
AppRegistry.registerComponent('TestRnImageUtil', () => TestRnImageUtil);